import { useState, useEffect, useCallback, useContext } from "../preact";

export default function Counter() {
    //let externalResult = external.func("Sciter")
    //const theme = useContext(Theme);
    const [value, setValue] = useState(0);
    const increment = useCallback(() => {
        setValue(value + 1);
    }, [value]);

    // https://zh-hans.reactjs.org/docs/hooks-effect.html
    // https://preactjs.com/guide/v10/hooks/#useeffect
    const [time, setTime] = useState(Date.now());
    useEffect(() => {
        let timer = setInterval(() => {
            setTime(Date.now());
        }, 1000);
        console.log('ef1')
        return function cleanup() {
            clearInterval(timer);
        };
        //return () => {}
    }, []);

    return (
        <div>
            <p>Active theme: 'theme'</p>
            <h2>
                当前时间:<span>{new Date(time).toLocaleTimeString()}</span>
            </h2>
            当前计数: {value}
            <br />
            <button onClick={increment}>
                Counter+1
            </button><br />
        </div>
    );
}